<?php
namespace app\admin\controller;

use system\model\Admin;
/**
 * 登入功能控制器
 * Class Login
 * @package app\admin\controller
 */
class Login
{
	public function index(Admin $admin)
	{
		//测试数据库连接
		//$res = Db::table('admin')->get();
		//p($res);
		//加密密码
		//$encrypted = Crypt::encrypt('admin');
		//var_dump($encrypted);

		//测试password_hash函数，php手册中搜索password就能搜索到
    	/*$password = password_hash('admin',PASSWORD_DEFAULT);
    	echo $password;

    	$bool = password_verify('admin',$password);
    	dd($bool);
		die;*/
		if(IS_POST)
		{
			$res = $admin->login();
			if($res['valid'])
			{
				//执行成功
				return message($res['msg'],'admin.entry.index','success');
			}else{
				//执行失败
				return message($res['msg'],'back','error');

			}
		}
		//加载模板文件
		return View::make();
	}
	public function code()
	{
		Code::width(100)->height(50)->num(4)->make();
	}
	/**
	 * 退出登录
	 */
	public function out()
	{
		//删除所有数据
		Session::flush();
		go(__ROOT__.'/login');
	}

	/**
	 * 修改密码
	 */
	public function pass()
	{
		Db::table('admin')->replace(['admin_id'=>1,'admin_password'=>'']);
	}

}